<template>
  <div class="login-container">
     <div class="loginTop">
        <img src="../../assets/img/loginTop.png" />
      </div>
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form login-formNew" auto-complete="on" label-position="left">
      <div class="logo">
        <img src="https://cdn.yueyangshuyuan.com/%E5%90%8E%E5%8F%B0logo.png" />
      </div>
      <div class="title-container">
        <h3 class="title">阅阳艾生活后台管理平台</h3>
      </div>

      <el-form-item prop="username">
        <!-- <span class="svg-container">
          <svg-icon icon-class="user" />
        </span> -->
        <el-input
          ref="username"
          v-model="loginForm.username"
          placeholder="请输入用户名"
          name="username"
          type="text"
          tabindex="1"
          auto-complete="on"
        />
      </el-form-item>

      <el-form-item prop="password">
        <!-- <span class="svg-container">
          <svg-icon icon-class="password" />
        </span> -->
        <el-input
          :key="passwordType"
          ref="password"
          v-model="loginForm.password"
          :type="passwordType"
          placeholder="请输入密码"
          name="password"
          tabindex="2"
          auto-complete="on"
          @keyup.enter.native="handleLogin"
        />
        <!-- <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
        </span> -->
      </el-form-item>

      <el-button :loading="loading" type="primary" class="sumitBtn"  @click.native.prevent="handleLogin">登录</el-button>

      <!-- <div class="tips">
        <span style="margin-right:20px;">username: admin</span>
        <span> password: any</span>
      </div> -->

    </el-form>
    <div class="footer">
       <p>阅阳（上海）健康管理咨询有限公司</p>
    </div>
  </div>
</template>

<script>
import { validUsername } from '@/utils/validate'
import request from '@/utils/request'

export default {
  name: 'Login',
  data() {
    const validateUsername = (rule, value, callback) => {
      // if (!validUsername(value)) {
      //   callback(new Error('请输入用户名'))
      // } else {
        callback()
      // }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: 'admin',
        password: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      console.log('handlelogin')
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            console.log(8888);
            this.$router.push({ path: '/mobile/bannerList' })
            this.loading = false
          }).catch((err) => {
            console.log(err)
            this.loading = false
          })
        } else {
          console.log(333)
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

.login-container {
  .el-input {
    display: inline-block;
    height: 44px;
  }
}
.login-formNew .el-form-item.is-success .el-input__inner,.login-formNew  .el-form-item.is-success .el-textarea__inner{
  border: 1px solid #DDDDDD !important;
  background-color: #fff !important;
  background: #fff !important;
}
.login-formNew .el-form-item.is-success .el-input__inner:focus,.login-formNew .el-form-item.is-success .el-textarea__inner:focus,.login-formNew .el-input.is-active .el-input__inner,.login-formNew .el-input__inner:focus {
  border: 1px solid #FF6A00 !important;
  border-color:#FF6A00 !important;
      background-color: #fff !important;
    background: #fff !important;
}
.login-container .el-input input:-webkit-autofill,input:-internal-autofill-previewed, input:-internal-autofill-selected, textarea:-internal-autofill-previewed, textarea:-internal-autofill-selected, select:-internal-autofill-previewed, select:-internal-autofill-selected {
  box-shadow:none !important;
      background-color: #fff !important;
    background: #fff !important;
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  .login-form {
    position: relative;
    width: 500px;
    max-width: 100%;
    padding: 3% 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title-container {
    position: relative;
    margin: 10% auto 5% auto;
    .title {
      font-size: 18px;
      color: #262626;
      text-align: center;
      font-weight: normal;
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
.loginTop {
  width:830px;
  margin:0 auto;
  img {
    display: block;
  }
}
.logo {
  width:271px;
  margin:0 auto;
}
.sumitBtn {
  outline:none;
  background:none;
  border:none;
  padding:0;
  margin:0;
  width:100%;
  height:44px;
  line-height:44px;
  background: #FF6A00;
  font-size: 16px;
  color: #FFFFFF;
  text-align:center;
}
.footer {
  width:500px;
  position: absolute;
  left:50%;
  margin-left:-250px;
  bottom:30px;
  p {
    width:100%;
    text-align:center;
    font-size: 12px;
    color: #CCCCCC;
  }
}
</style>
